home *** CD-ROM | disk | FTP | other *** search
- #pragma mark Header
- /***************************/
- /* DebugAids.c
- This file contains some generic debugging aids
- 6/5/91 - created by Kirk Chase */
- /***************************/
-
- #pragma mark #includes
- #include <stdio.h>
- #include <signal.h>
- #include <errno.h>
- #include <assert.h>
-
- #include "DebugAids.h"
-
- #pragma mark #defines
- #ifndef TRUE
- #define TRUE (1)
- #define FALSE (0)
- #endif
-
- #pragma mark Externals
- extern jmp_buf env;
-
- #pragma mark Static Globals
- static int __userAbort = FALSE;
-
- /* CheckOptionAbort()
- Routine to look for option key pressed.
- returns TRUE if there was, FALSE if none */
- CheckOptionAbort(void)
- {
- #ifdef THINK_C
- KeyMap debugKeys;
-
- GetKeys(&debugKeys);
- if (debugKeys.Key[1] & 0x4) {
- SigHandler(SIGINT);
- return(TRUE);
- }
-
- #endif
-
- return(FALSE);
- }
-
- /* UserAbort()
- Routine to set user abort flag.
- jumps to signal handling software sending SIGINT */
- void UserAbort(int sig)
- {
- __userAbort = TRUE;
- longjmp(env, SIGINT);
- }
-
- /* SigHandler(int sig)
- Sets up signals (sig=0) or handles them (sig=anything) */
- SigHandler(int sig)
- {
- switch (sig) {
- case 0: /* set up signals */
- assert(signal(SIGINT, &UserAbort) != SIG_ERR);
- break;
- case SIGINT: /* User abort, cmd-. */
- signal(SIGINT, &UserAbort);
- __userAbort = FALSE;
- #ifdef DEBUG
- fprintf(stderr,"\n***User Interrupt***\n");
- #ifdef DEBUGGER
- DebugStr("\p***User Interrupt***");
- #endif
- #endif
- break;
- default: /* unknown signal */
- #ifdef DEBUG
- fprintf(stderr,"\n***Unknown Signal***%d\n", sig);
- #endif
- break;
- }
- }